package com.collect.common.utils.sensitive;

import com.collect.common.redis.RedisCache;
import com.collect.common.redis.RedisKeyUtils;
import com.collect.common.utils.ik.IKAnalyzerSupport;
import com.collect.common.utils.spring.SpringUtils;
import com.collect.discord.web.domain.SensitiveWord;
import net.dv8tion.jda.api.entities.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author :hky
 * @ Date  : Created in 14:11 2022-09-28
 * @ Version :discord
 * @ Decribtion : 敏感词工具类$
 */
public class SensitiveWordUtils {

    /**
     * 通过IK分词器，处理敏感词
     * @param messageContent 消息内容
     * @return
     */
    public static List<String> dealIk(String messageContent){
        List<String> iKList = IKAnalyzerSupport.iKSegmenterToList(messageContent);
        RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
        List<String> sensitiveList=new ArrayList<>();
        for (String ik : iKList) {
            SensitiveWord sensitiveWord = redisCache.getCacheMapValue(RedisKeyUtils.SENSITIVE, ik.toLowerCase());
            if(null != sensitiveWord){
                sensitiveList.add(sensitiveWord.getWord());
            }
        }
        return sensitiveList;
    }
}
